/** 
 * @jsName: LetterInfoManaged.js 
 * @author Sean Cui
 * @date 2017-04-16 下午3:46:00 
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @version V1.0.0.0
 * @comment 该文件通过代码生成器生成，如果修改次文件后，重新生成时将覆盖修改内容，请修改生成模板或做好备份
 */

var LetterInfoManaged = function() {
	return {
		datatable : null,
		init : function() {
			/*$('#search_expressTime').datetimepicker({
        		lang:'ch',
        		timepicker:false,
        		format:'Y-m-d'
        	});*/
			this.initSearch();
			this.initListener();
		},
		initSearch : function() {
			if (!jQuery().dataTable) {
				return;
			}
			var listTable = $("#LetterInfoListTable").dataTable({
				"sAjaxSource" : ctx + "/letterInfo/search?now=" + new Date().getTime(),
				/* 使用post方式 */
				"fnServerData" : function(sSource, aoData, fnCallback) {
					var postData = {
						page : 1,
						start : 0,
						rows : 10,
						params : {'letterInfoState':1}
					};
					
					if($('#search_insureCompany').val()){
						postData.params.insureCompany = "%"+($('#search_insureCompany').val()).replace(/\s/g,"%")+"%";
					}
					if($('#search_orderNo').val()){
						postData.params.orderNo = "%"+($('#search_orderNo').val()).replace(/\s/g,"%")+"%";
					}
					if($('#search_receiverMan').val()){
						postData.params.receiverMan = "%"+($('#search_receiverMan').val()).replace(/\s/g,"%")+"%";
					}
					if($('#search_receiverPhone').val()){
						postData.params.receiverPhone = "%"+($('#search_receiverPhone').val()).replace(/\s/g,"%")+"%";
					}
					if($('#search_expressTime').val()){
						postData.params.expressTime = ($('#search_expressTime').val());
					}
					if($('#search_expressCompany').val()){
						postData.params.expressCompany = "%"+($('#search_expressCompany').val()).replace(/\s/g,"%")+"%";
					}

					// 参数
					for (var i = 0, size = aoData.length; i < size; i++) {
						if (aoData[i].name == 'iDisplayLength') {
							postData.rows = aoData[i].value;
						} else if (aoData[i].name == 'iDisplayStart') {
							postData.start = aoData[i].value;
						} else if (aoData[i].name == 'sEcho') {
							postData.page = aoData[i].value;
						}
					}

					$.ajax({
						"dataType" : 'json',
						"type" : "POST",
						"cache": false,
						"url" : sSource,
						"data" : postData,
						"success" : function(data, textStatus, jqXHR){
							fnCallback(data.data, textStatus, jqXHR);
						}
					});
				},
				"bAutoWidth":false,
				"aoColumnDefs" : [
						{
							"data" : "index",
							"aTargets" : [ 0 ]
						},
						{
							"data" : "insureCompany",
							"aTargets" : [ 1 ]
						},
						{
							"data" : "orderNo",
							"aTargets" : [ 2 ]
						},
						{
							"data" : "receiverMan",
							"aTargets" : [ 3 ]
						},
						{
							"data" : "receiverPhone",
							"aTargets" : [ 4 ]
						},
						{
							"data" : "expressNo",
							"aTargets" : [ 5 ]
						},
						{
							"data" : "expressCompany",
							"aTargets" : [ 6 ]
						},
						/*{
							"data" : "expressTime",
							"aTargets" : [ 7 ]
						},*/
						{
							"aTargets" : [ 7 ],
							"mRender" : function(data, type, full) {
								var btns =  '';
								btns +=  '<button title="" href="javascript:;" class="btn btn-sm-table btn-primary" name="del" target_id="'+full.id+'">查看详情</button>';
								return btns;
							}
						}
				]
			});
			this.datatable = listTable;
		},reSearch:function(){
        	this.datatable.fnDraw();
        },removeClass:function(){//去除Form表单的验证样式
        	$('.form-group','#actForm').removeClass('has-success')
            .removeClass('has-error');
    		 $('span').remove('.help-block');
        },initListener : function() {
			/*
			 * 查询
			 */
			$("#searchBtn").click(function() {
				LetterInfoManaged.reSearch();
				return false;
			});

			/*
			 * 清除
			 */
			$("#clearBtn").click(function() {
				$("#searchForm")[0].reset();
				return false;
			});

			/**
			 * 查看详情
			 */
			$('#LetterInfoListTable tbody').on('click', 'button[name="del"]',function() {
				var id = $(this).attr("target_id");
				window.location.href = ctx + '/letterInfo/'+id+'/details.html';
			});
		},
		
	};

}();

/*
 * Powered By [Code-Generator]
 * Web Site: http://www.hwelltech.com
 */

